package com.jike.buyi.filter;

import com.jike.buyi.contents.WebContens;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class MyFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        String contextPath = request.getContextPath();
        HttpSession session = request.getSession();
        HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse) servletResponse);

/*        if( session.getAttribute(WebContens.SESSION_UER) != null ) {
            filterChain.doFilter(servletRequest, servletResponse);
        }else if(request.getRequestURI().indexOf("/index") != -1 ||
                request.getRequestURI().indexOf("/login") != -1 ||
                request.getRequestURI().indexOf("/common") != -1){
            filterChain.doFilter(servletRequest, servletResponse);
        }else {
           // filterChain.doFilter(servletRequest, servletResponse);
            wrapper.sendRedirect(contextPath+"/index");
        }*/

        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }
}
